package net.lainiao.mycost.service.impl;

import net.lainiao.mycost.bean.UserInfo;
import net.lainiao.mycost.dao.IUserInfoDAO;
import net.lainiao.mycost.service.IUserInfoService;
import net.lainiao.mycost.utils.Comm;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.concurrent.locks.Condition;

/**
 * Created by Administrator on 2017/3/22.
 */
@Service
@Transactional
public class UserInfoServiceImpl implements IUserInfoService {

    @Autowired
    private IUserInfoDAO dao;

    @Override
    public void add(UserInfo info) {
        dao.add(info);
    }

    @Override
    public UserInfo getUser(UserInfo info) {
        return dao.getUser(info);
    }

    @Override
    public List<UserInfo> list(UserInfo info) {
        condition(info);
        return dao.list(info);
    }

    private void condition(UserInfo info) {
        if(info!=null){
            if(StringUtils.isNotEmpty(info.getUserName())){
                info.setUserName("%"+info.getUserName()+"%");
            }
        }
    }

    @Override
    public long getCount(UserInfo info) {
        condition(info);
        return dao.getCount(info);
    }

    @Override
    public void update(UserInfo userInfo) {
        dao.update(userInfo);
    }

    @Override
    public void detele(Integer[] userIds) {
        for(Integer id:userIds){
            UserInfo userInfo=new UserInfo();
            userInfo.setUserId(id);
            userInfo.setUserMark(Comm.MARK_NO);
            dao.update(userInfo);
        }
    }

    @Override
    public UserInfo isLogin(UserInfo userInfo) {
        return dao.login(userInfo);
    }
}
